package cn.tedu.hospitalqd.controller;

import cn.tedu.hospitalqd.pojo.dto.IntroAddNewDTO;
import cn.tedu.hospitalqd.pojo.dto.IntroUpdateDTO;
import cn.tedu.hospitalqd.pojo.vo.DoctorListItemVO;
import cn.tedu.hospitalqd.pojo.vo.IntroListItemVO;
import cn.tedu.hospitalqd.pojo.vo.IntroStandarVO;
import cn.tedu.hospitalqd.service.IntroService;
import cn.tedu.hospitalqd.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/intros")
@Api(tags = "04. 医院简介表")
@Validated
public class IntroController {
    @Autowired
    private IntroService introService;

    // http://localhost:9080/albums/add-new?name=TestName001&description=TestDescription001&sort=199
    @PostMapping("/add-new")
    @ApiOperation("添加医院简介")
    @ApiOperationSupport(order = 100)
    public JsonResult addNew(@Valid IntroAddNewDTO introAddNewDTO) {
        log.debug("开始处理【添加医院简介】的请求，参数：{}", introAddNewDTO);
        introService.addNew(introAddNewDTO);
        return JsonResult.ok();
    }

    // http://localhost:9080/albums/9527/delete
    @PostMapping("/{id:[0-9]+}/delete")
    @ApiOperation("根据ID删除医院简介")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "医院简介ID", required = true, dataType = "long")
    })
    public JsonResult delete(@Range(min = 1, message = "删除医院简介失败，ID值无效！")
                             @PathVariable Long id) {
        introService.delete(id);
        return JsonResult.ok();
    }

    // http://localhost:9080/albums/9527/update
    @PostMapping("/{id:[0-9]+}/update")
    @ApiOperation("修改医生医院简介")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "医院简介ID", required = true, dataType = "long")
    })
    public JsonResult updateInfoById(@Range(min = 1, message = "修改医院简介详情失败，ID值无效！")
                                     @PathVariable Long id, @Valid IntroUpdateDTO introUpdateDTO) {
        introService.updateInfoById(id,introUpdateDTO);
        return JsonResult.ok();
    }

    // http://localhost:9080/albums/9527
    @GetMapping("/{id:[0-9]+}")
    @ApiOperation("根据ID查询医院简介详情")
    @ApiOperationSupport(order = 410)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "医院简介ID", required = true, dataType = "long")
    })
    public JsonResult getStandardById(@Range(min = 1, message = "获取医院简介详情失败，ID值无效！")
                                      @PathVariable Long id) {
        IntroStandarVO queryResult = introService.getStandardById(id);
        return JsonResult.ok(queryResult);
    }

    // http://localhost:9080/albums
    @GetMapping("")
    @ApiOperation("查询医院简介列表")
    @ApiOperationSupport(order = 420)
    public JsonResult list() {
        List<IntroListItemVO> list = introService.list();
        return JsonResult.ok(list);
    }
}
